from typing import List, Optional
from dataclasses import dataclass


from dto.strategy_assessment import RiskAssessment
from service.das.stock_monitor_das import AntMonitorStock


@dataclass
class StrategyCalculateResult:

    # 策略评估的结果列表
    risk_assessments: List[RiskAssessment]

    # 计算的总得分
    total_score: int

    # 风险等级（1-10）
    risk_level: int

    # 关注等级（1-10）
    focus_level: int

    # 最新股价
    latest_price: Optional[float] = None

    monitor: AntMonitorStock

    def __post_init__(self):
        """
        初始化时计算风险等级和关注等级
        """
        if not self.risk_assessments:
            self.total_score = 0
            self.risk_level = 1
            self.focus_level = 1
        else:
            # 计算总得分
            self.total_score = sum(ra.node_point for ra in self.risk_assessments)

            # 计算风险等级，假设风险等级基于总得分按比例映射到 1-10
            self.risk_level = min(max(self.total_score // 10, 1), 10)

            # 计算关注等级，假设关注等级为风险等级的倒数映射（简单示例）
            self.focus_level = 11 - self.risk_level

    def __str__(self):
        return (
            f"Total Score: {self.total_score}, "
            f"Risk Level: {self.risk_level}, "
            f"Focus Level: {self.focus_level}, "
            f"Risk Assessments: {[ra.description for ra in self.risk_assessments]}"
        )
